import java.util.Scanner;

public class MaxSubarraySumWithScanner {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        int length = scanner.nextInt();
        
        int[] nums = new int[length];
        
        for (int i = 0; i < length; i++) {
            nums[i] = scanner.nextInt();
        }
        
        int maxSum = maxSubarraySum(nums);
        System.out.println(maxSum);
        
        scanner.close();
    }
    
    public static int maxSubarraySum(int[] nums) {
        
        int currentMax = nums[0];
        int globalMax = nums[0];
        
        for (int i = 1; i < nums.length; i++) {
            currentMax = Math.max(nums[i], currentMax + nums[i]);
            globalMax = Math.max(globalMax, currentMax);
        }
        
        return globalMax;
    }
}
    